<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body{
            margin:0;
            padding:0;
        }
        .container{
            width:820px;
            height:375px;
            margin:0 auto;
            position:relative;
            margin-top:20px;
        }
        .nav{
            position:absolute;
            width:820px;
            text-align: center;
            bottom:0;
            height:35px;
            line-height:35px;
            background:#aaa;
            box-sizing: border-box;
        }
        .nav a{
            box-sizing: border-box;
            width:164px;
            float:left;
            text-decoration:none;
            color:#424242;
            font-size:14px;
        }
        .nav a.on{
            background:#fff;
            color:#ab8e66;
            border-bottom:2px solid #cea861;
        }
        .img img{
            vertical-align:bottom;
            position:absolute;
            top:0;
        }
        .img img:nth-child(2){
            display:none;
        }
        .img img:nth-child(3){
            display:none;
        }
        .img img:nth-child(4){
            display:none;
        }
        .img img:nth-child(5){
            display:none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="nav">
            <a href="" class="on">限时折扣</a>
            <a href="">MSI宝典</a>
            <a href="">RNG VS DK</a>
            <a href="">全球总决赛</a>
            <a href="">格温周边商城</a>
        </div>
        <div class="img">
            <img src="images/01.jpeg" alt="">
            <img src="images/02.jpeg" alt="">
            <img src="images/03.jpeg" alt="">
            <img src="images/04.jpeg" alt="">
            <img src="images/05.jpeg" alt="">
        </div>
    </div>
    <script>
        var nav=document.querySelectorAll('.nav a');
        var img=document.querySelectorAll('.img img');
        var cur=0;
        var timer;
        console.log(nav,img);
        nav.forEach(function(v,i){
            v.onmouseover=function(){
                play(i);
                cur=i;
                clearInterval(timer);
            }
            v.onmouseout=function(){
                autoplay();
            }

        });
        function play(n){
            img.forEach(function(v1){
                v1.style.display='none';
            });
            nav.forEach(function(v2){
                v2.className='';
            });
            nav[n].className='on';
            img[n].style.display='block';
        }
        function autoplay(){
            timer=setInterval(function(){
                cur++;
                play(cur%nav.length);
            },2000)
        }
        autoplay();
    </script>
</body>
</html>